package org.study.mybatisplus.dynamic.boot.vo;

import cn.hutool.core.annotation.Alias;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;

import java.io.Serializable;

/**
 * 设备属性导出响应参数
 * <p>
 * 注解 @JSONField：使用 fastjson 序列化、反序列化时，指定key名称
 * 注解 @Alias：使用 hutool 工具包导出 Excel、CSV 时，指定表头
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2025年02月12日
 */
@Data
public class DevicePropertyExportVO implements Serializable {
    private static final long serialVersionUID = 1L;

    @JSONField(name = "deviceId", ordinal = 10)
    @Alias(value = "设备ID")
    private String deviceId;

    @JSONField(name = "gatewayNo", ordinal = 13)
    @Alias(value = "网关编号")
    private String gatewayNo;

    @JSONField(name = "deviceNo", ordinal = 15)
    @Alias(value = "设备SN")
    private String deviceNo;

    @JSONField(name = "deviceName", ordinal = 17)
    @Alias(value = "设备名称")
    private String deviceName;

    @JSONField(name = "propertyId", ordinal = 21)
    @Alias(value = "属性ID")
    private String propertyId;

    @JSONField(name = "propertyNo", ordinal = 23)
    @Alias(value = "属性编号")
    private String propertyNo;

    @JSONField(name = "propertyName", ordinal = 25)
    @Alias(value = "属性名称")
    private String propertyName;

    /**
     * 1-时间戳-TIMESTAMP
     * 2-整型-INT
     * 3-长整型-BIGINT
     * 4-单精度浮点型-FLOAT
     * 5-双精度浮点型-DOUBLE
     * 6-单字节字符串-BINARY
     * 7-多字节字符串-NCHAR
     * 8-短整型-SMALLINT
     * 9-单字节整型-TINYINT
     * 10-布尔型-BOOL
     */
    @JSONField(name = "propertyType", ordinal = 27)
    @Alias(value = "属性类型")
    private String propertyType;

    @JSONField(name = "propertyScale", ordinal = 29)
    @Alias(value = "属性精度")
    private String propertyScale;

    @JSONField(name = "propertyUnit", ordinal = 31)
    @Alias(value = "属性单位")
    private String propertyUnit;

    private String convertPropertyTypeToCode(String propertyType) {
        return switch (propertyType) {
            case "1", "时间戳", "TIMESTAMP" -> "1";
            case "2", "整型", "INT" -> "2";
            case "3", "长整型", "BIGINT" -> "3";
            case "4", "单精度浮点型", "FLOAT" -> "4";
            case "5", "双精度浮点型", "DOUBLE" -> "5";
            case "6", "单字节字符串", "BINARY" -> "6";
            case "7", "多字节字符串", "NCHAR" -> "7";
            case "8", "短整型", "SMALLINT" -> "8";
            case "9", "单字节整型", "TINYINT" -> "9";
            case "10", "布尔型", "BOOL" -> "10";
            default -> "7";
        };
    }
}
